package com.jvyou.framework.controller;



import com.jvyou.framework.domain.dto.DictDataDto;
import com.jvyou.framework.domain.entity.DictData;
import com.jvyou.framework.service.DictDataService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import java.util.List;
import com.jvyou.common.annotation.Log;
import com.jvyou.common.core.domain.model.PageResult;
import com.jvyou.common.core.domain.model.Result;
import com.jvyou.common.enums.log.BusinessType;
import com.jvyou.common.enums.result.HttpCodeEnum;


/**
 * 字典数据表(DictData)表控制层
 *
 * @author 橘柚
 * @since 2025-05-30 15:24:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/dictData")
public class DictDataController  {
    
    private final DictDataService dictDataService;
    
     /**
     * 查询字典数据表列表
     *
     * @param dto 查询参数
     * @return 字典数据表
     */
    @GetMapping("/list")
    @SaCheckPermission("sys:dictData:list")
    @Log(title = "查询字典数据表列表", businessType = BusinessType.OTHER)
    public Result<List<DictData>> list(@ModelAttribute DictDataDto dto) {
        return Result.success(dictDataService.listDictData(dto));
    }

     /**
     * 分页查询字典数据表列表
     *
     * @param dto 查询参数
     * @return 字典数据表
     */
    @GetMapping("/page")
    @SaCheckPermission("sys:dictData:page")
    @Log(title = "分页查询字典数据表列表", businessType = BusinessType.OTHER)
    public Result<PageResult<DictData>> page(@ModelAttribute DictDataDto dto) {
        return Result.success(dictDataService.pageDictData(dto));
    }

    /**
     * 通过主键查询字典数据表单条
     *
     * @param id 字典数据表主键
     * @return 字典数据表
     */
    @GetMapping("/{id}")
    @Log(title = "通过主键查询字典数据表")
    @SaCheckPermission("sys:dictData:get")
    public Result<DictData> selectOne(@PathVariable("id") Long id) {
        return Result.success(dictDataService.getById(id));
    }

    /**
     * 新增字典数据表
     *
     * @param dictData 字典数据表实体对象
     * @return 新增字典数据表结果
     */
    @PostMapping
    @Log(title = "新增字典数据表",  businessType = BusinessType.INSERT)
    @SaCheckPermission("sys:dictData:insert")
    public Result<DictData> insert(@RequestBody DictData dictData) {
        boolean success = dictDataService.save(dictData);
        return success ? Result.success(dictData) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改字典数据表
     *
     * @param dictData 字典数据表实体对象
     * @return 修改字典数据表结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("sys:dictData:update")
    @Log(title = "修改字典数据表数据", businessType = BusinessType.UPDATE)
    public Result<DictData> updateById(@RequestBody DictData dictData) {
        boolean success = dictDataService.updateById(dictData);
        return success ? Result.success(dictData) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除字典数据表数据
     *
     * @param id 字典数据表主键
     * @return 删除字典数据表结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:dictData:delete")
    @Log(title = "删除字典数据表",  businessType = BusinessType.DELETE)
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        boolean success = dictDataService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

